<?php 
$cs=Yii::app()->clientScript;
$cs->registerScriptFile('./js/freezePane.js');
$cs->registerScript('business_statistics',<<<END
function check_type(){
	if($("select[name=b_type]").val()==0)
		$("#ctype").show();
	else
		$("#ctype").hide();		
}
$("select[name=b_type]").change(check_type);
check_type();

$("#excel").click(
function(){
	if($("#s_date").val()=='') {alert("请输入业务时间!");return;}
	var act=$("form").attr('action');
	$("form").attr('action',act+'&excel=1');
	$("form").attr('target','_blank');
	$("form").submit();
	$("form").attr('action',act);
	$("form").attr('target','');
}
);
$("#freezePane_cb").click(freezePane);
END
);
?>
<h2>年统计表</h2>
<?php echo CHtml::beginForm();?>
<table  style="margin: 0 auto;"  width="1210px">
<tr><td>
	业务类型：<?php echo CHtml::dropDownList('b_type', isset($_POST['b_type'])?$_POST['b_type']:'', array('0'=>'运输','1'=>'仓储','2'=>'装卸'));?>&nbsp;&nbsp;&nbsp;&nbsp;
	<span id="ctype">承运方:<?php echo CHtml::dropDownList('c_type', isset($_POST['c_type'])?$_POST['c_type']:'', array('2'=>'全部','0'=>'自有车','1'=>'第三方'));?>&nbsp;&nbsp;&nbsp;&nbsp;</span>
	业务时间:<input type="text" id="s_date" name="s_date" size="7" value="<?php echo isset($_POST['s_date'])?$_POST['s_date']:'';?>"/>&nbsp;&nbsp;&nbsp;&nbsp;
	<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'s_date','ifFormat'=>'%Y'));?>
	<input type="submit" value="搜索"/>&nbsp;&nbsp;&nbsp;&nbsp;<input id="excel" type="button" value="输出excel文件"/>
	&nbsp;&nbsp;&nbsp;&nbsp;<input id="freezePane_cb" class="#freezePane" type="checkbox"><label for="freezePane_cb">冻结标题</label>
</td></tr></table>
<?php echo CHtml::endForm();?>
<table id="freezePane" class="dataGrid" width="1210px">
  <thead>
  <tr>
    <th width="100" >客户名称</th>
    <th width="50">款项</th>
    <th width="80">1月份</th>
    <th width="80">2月份</th>
    <th width="80">3月份</th>
    <th width="80">4月份</th>
    <th width="80">5月份</th>
    <th width="80">6月份</th>
    <th width="80">7月份</th>
    <th width="80">8月份</th>
    <th width="80">9月份</th>
    <th width="80">10月份</th>
    <th width="80">11月份</th>
    <th width="80">12月份</th>
    <th width="100">总计</th>
  </tr>
  </thead>
  <tbody>
  <?php if(isset($customer_models)):?>
<?php
$titles=array('truck_times'=>'车次','tonnage'=>'吨位','receivable_amount'=>'应收','payable_amount'=>'应付',
'disparity'=>'差价','disparity_ratio'=>'差价率');
$month=array('01','02','03','04','05','06','07','08','09','10','11','12');
$j=-1;
?>
<?php foreach($customer_models as $name=>$model):$j++?>
  <?php foreach($titles as $n=>$title):?>
  <tr class="<?php echo $j%2?'even':'odd';?>">
    <?php if($n=='truck_times'):?><td width="100" rowspan="6"><?php echo $name;?></td><?php endif;?>
    <td width="50"><?php echo $title;?></td>
	<?php foreach($month as $m):?>   
    <td><?php if(isset($model[$m])) echo $model[$m]->$n;?></td>
    <?php endforeach;?>
    <td><?php echo $sum_models[$j]->$n;?></td>
  </tr>
  <?php endforeach;?>
<?php endforeach;?>
  <?php foreach($titles as $n=>$title):?>
  <tr class="<?php echo $j%2?'odd':'even';?>">
    <?php if($n=='truck_times'):?><td rowspan="6"><?php echo '合计';?></td><?php endif;?>
    <td><?php echo $title;?></td>
	<?php foreach($month as $m):?>   
    <td><?php if(isset($sum1_models[$m])) echo $sum1_models[$m]->$n;?></td>
    <?php endforeach;?>
    <td><?php echo $sum2_models->$n;?></td>
  </tr>
  <?php endforeach;?>
<?php endif;?>
  </tbody>
</table>
<br/>
<?php if(!isset($customer_models)):?>
 <h4 id="no_record" style="text-align:center;">暂时没有符合要求的记录!</h4>
<?php endif;?>